<?php

namespace backend\models;

use Yii;

/**
 * This is the model class for table "edu_enter".
 *
 * @property int $id
 * @property string $title 入驻礼包名称
 * @property string $image 海报图
 * @property string $price 价格
 * @property string $equity 权益说明
 * @property int $status 0禁用 1启用
 * @property int $create_time 创建时间
 */
class EduEnter extends \yii\db\ActiveRecord
{

    //定义场景
    const SCENARIO_UPDATE = 'update';
    const SCENARIO_UPLOAD = 'upload';
    const SCENARIO_CREATE = 'create';

    //定义只有两种状态的枚举
    const STATUS_DISABLE = 0; //禁止
    const STATUS_ENABLE = 1; //启用

    public $file;

    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'edu_enter';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['price'], 'number'],
            [['price', 'title', 'image'], 'required'],
            [['equity'], 'string'],
            [['status', 'create_time'], 'integer'],
            [['title'], 'string', 'max' => 100],
            [['image'], 'string', 'max' => 500],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'title' => '标题',
            'image' => '海报',
            'price' => '价格',
            'equity' => '权益条例',
            'status' => '状态',
            'create_time' => '创建时间',
        ];
    }

    /**
     * @return string
     * 获取status状态
     */
    public function getStatusValue()
    {
        return $this->status == self::STATUS_ENABLE ? '启动' : '禁用';
    }

    /**
     * @param $column
     * @param null $value
     * @return bool|mixed
     * 转化到gridview搜索
     */
    public static function dropDown($column, $value = null)
    {
        $dropDownList = [
            'isEnable' => [
                '0' => '禁用',
                '1' => '启用',
            ],
        ];

        if (null !== $value) {
            return array_key_exists($column, $dropDownList) ? $dropDownList[$column][$value] : false;
        } else {
            return array_key_exists($column, $dropDownList) ? $dropDownList[$column] : false;
        }
    }

    /**
     * @return array
     * 获取状态
     */
    public static function allStatus()
    {
        return [self::STATUS_ENABLE=>'启用',self::STATUS_DISABLE=>'禁用'];
    }

    /**
     * @return array
     * 定义场景
     */
    public function scenarios()
    {
        $scenarios = parent::scenarios();
        $scenarios[self::SCENARIO_UPDATE] = ['title', 'image', 'price', 'equity', 'status', 'create_time'];
        $scenarios[self::SCENARIO_UPLOAD] = ['file'];
        $scenarios[self::SCENARIO_CREATE] = ['title', 'image', 'price', 'equity', 'status', 'create_time'];
        return $scenarios;
    }
}
